package com.ahsjdy.stcommon.holder;

public class PageHolder {
    public int prePageNum = 2;

    private int currentPage;
    private int totalPage;
    private int offset;
    private int totalElement;
    private Object data;

    private PageHolder(int currentPage, int totalElement, int prePageNum) {
        this.currentPage = currentPage;
        this.totalElement = totalElement;
        this.prePageNum = prePageNum;
    }

    public static PageHolder build(int currentPage, int totalElement, int prePageNum) {
        PageHolder pageHolder = new PageHolder(currentPage, totalElement, prePageNum);
        pageHolder.processOffset();
        pageHolder.processTotalPage();
        return pageHolder;
    }

    private int processOffset() {
        offset = (currentPage - 1) * prePageNum;
        return offset;
    }

    private int processTotalPage() {
        totalPage = totalElement % prePageNum  == 0 ? totalElement / prePageNum : (totalElement / prePageNum) + 1;
        return totalPage;
    }

    public int getPrePageNum() {
        return prePageNum;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public int getTotalElement() {
        return totalElement;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getOffset() {
        return offset;
    }

}
